/*jslint browser: true, devel: true, bitwise: true, white: true, plusplus: true */
/*global $:true, define:true */

/**
 * @module UI
 */

define(['WID/UI/Widget'],function(Widget) {
"use strict";

/** 
 * One line text field. This field can be password field.
 * @class TextField
 * @constructor
 * @param {Object} props Parameters. See also in {{#crossLink "Widget"}}{{/crossLink}}
 *  @param {String} [props.value] Text for field.
 *  @param {Boolean} [props.password] If true this field be password field.
 *  @param {Number} [props.size] Size field, amount of visibled characters in field.
 *  @param {Number} [props.length] Max field text length in characters.
 *  @param {Boolean} [props.readOnly] If true the field be only readable.
 */
function TextField(props) {
	props = props||{};
	Widget.call(this,props,'input');
	this.Type = TextField.TYPE_TEXT;

	this.value = props.value||'';
	this.type = props.password;
	this.size = props.size||TextField.SIZE;
	this.length = props.length||TextField.LENGTH;
	this.readOnly = props.readOnly||TextField.READ_ONLY;
	
	
} var extend = Object.create(Widget.prototype); extend.constructor = TextField;

TextField.TYPE_TEXT = 0;
TextField.TYPE_PASSWORD = 1;
TextField.SIZE = 20;
TextField.LENGTH = 500;
TextField.READ_ONLY = false;

Widget.defineProps(extend,{
	type: {
		get: function() {
			return this.Type;
		},
		set: function(password) {
			if (password) {
				this.Type = TextField.TYPE_PASSWORD;
				this.ntv.type = 'password';
			} else {
				this.Type = TextField.TYPE_TEXT;
				this.ntv.type = 'text';
			}
		}
	},
	
	value: {
		get: function() {
			return this.ntv.value;
		},
		set: function(value) {
			this.ntv.vlaue = value;
		}	
	},
	
	size: {
		get: function() {
			return this.ntv.size;
		},
		set: function(size) {
			this.ntv.size = size;
		}
	},
	
	length: {
		get: function() {
			return this.ntv.maxLength;
		},
		set: function(max) {
			this.ntv.maxLength = max;
		}
	},
	
	readOnly: {
		get: function() {
			return this.ntv.readOnly;
		},
		set: function(readOnly) {
			this.ntv.readOnly = readOnly;
		}
	}
});
TextField.prototype = extend;
return TextField;
});
